/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tmPHA;

import java.awt.Point;

/**
 *
 * @author squirrel
 * 
 * Esta es la matriz base tanto para la R como la Q
 *
 */
public class Environment {
    public double[][] matriz;
    public Point mapSize;
    public Pheromone[][] fCC;
    public Pheromone[][] fCH;
    public Pheromone[][] fCE;
    public Environment(int m, int n){
        mapSize=new Point();
        mapSize.x=(m*2)-1;
        mapSize.y=(n*2)-1;
        matriz=new double[mapSize.x][mapSize.y];
        fCC = new Pheromone[mapSize.x][mapSize.y];
        fCH = new Pheromone[mapSize.x][mapSize.y];
        fCE = new Pheromone[mapSize.x][mapSize.y];
        Fill();
        Create_Pheromones();
    }
    public void Create_Pheromones(){
        for(int i=0;i<mapSize.x;i++){
            for(int j=0;j<mapSize.y;j++){
                fCC[i][j] = new Pheromone (1);
                fCH[i][j] = new Pheromone (2);
                fCE[i][j] = new Pheromone (3);
            }
        }
    }
    public void Fill(){
        for(int i=0;i<mapSize.x;i++){
            for(int j=0;j<mapSize.y;j++){
                matriz[i][j]=0;
            }
        }
    }
    public Point getDim(){
        return mapSize;
    }
    public double getElement(int i, int j){
        return matriz[i][j];
    }
    public void setElement(int i, int j, double value){
        matriz[i][j]=value;
    }
    public void printEnv(){
        for(int i=0;i<mapSize.x;i++){
            for(int j=0;j<mapSize.y;j++){
                System.out.print(matriz[i][j]+" ");
            }
            System.out.println();
        }
    }
    void addFeromona(int x, int y, int tipo, double cantidad){
        if(tipo == 1){
            fCE[x][y].incrementar(cantidad);
        }else if (tipo == 2){
            fCC[x][y].incrementar(cantidad);
        }else if (tipo == 3){
            fCH[x][y].incrementar(cantidad);
        }
    }
    void evaporarFeromona(){
        for(int i=0;i<mapSize.x;i++){
            for(int j=0;j<mapSize.y;j++){
                fCE[i][j].evaporar();
                fCC[i][j].evaporar();
                fCH[i][j].evaporar();
            }
        }
    }
    double f1_conc(int x, int y){
        return fCE[x][y].concentracion();
    }
    double f2_conc(int x, int y){
        return fCC[x][y].concentracion();
    }
    double f3_conc(int x, int y){
        return fCH[x][y].concentracion();
    }
    
}
